package com.aop.demo.annotation;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect // 标注为切面
public class Audience {
    // 定义切入点
    public static final String POINT_CUT = "execution(public java.lang.String com.aop.demo.annotation.Actor.do*(..))";

    /*@Before(POINT_CUT)
    public void before(JoinPoint point) {
        System.out.println(point.getSignature().getName());
        System.out.println(point.getTarget().getClass());
        System.out.println("关闭手机");
    }

    @After(POINT_CUT)
    public void after() {
        System.out.println("鼓掌......");
    }

    @AfterThrowing(POINT_CUT)
    public void throwing() {
        System.out.println("表演太难看了");
    }

    @AfterReturning(POINT_CUT)
    public void leave() {
        System.out.println("观众离场");
    }*/
    
    @Around(POINT_CUT) 
    public Object proxy(ProceedingJoinPoint pjp) {
    	Object result = null;
    	
    	System.out.println("关闭手机，找座位");
    	try {
			result = pjp.proceed();
			System.out.println("鼓掌......");
		} catch (Throwable e) {
			e.printStackTrace();
			System.out.println("演的太难看了");
		}
    	System.out.println("观众离场");
    	
    	return result;
    }
}
